﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLNS_v1.Form;
using QLNS_v1.Bus;

namespace QLNS_v1
{
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        public frmMain()
        {
            InitializeComponent();
            
            
        }

        private void barNhanVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            uclNhanVien sv = new uclNhanVien();
            sv.Dock = DockStyle.Fill;
            tabNhanVien.Controls.Add(sv);
            tabNhanVien.PageVisible = true;
            tabMain.SelectedTabPage = tabNhanVien;
            this.Cursor = Cursors.Default;
        }

        private void btnTinhLuong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            QLNS_v1.Bus.ChamCong_Bus ccb = new Bus.ChamCong_Bus();
            int maxthang = ccb.GetMaxThang(DateTime.Now.Month,DateTime.Now.Year);
            if (maxthang != -1)
            {
               DialogResult re= XtraMessageBox.Show("Tháng này chưa tạo bảng chấm công, Bạn có muốn tạo bảng chấm công không","Thông báo",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
               if (re == DialogResult.Yes)
               {
                   NhanVien_Bus nvb=new NhanVien_Bus();
                   
                   List<NhanVien_BTO> listnhanvien = nvb.ListNhanVien();
                   foreach (var a in listnhanvien)
                   {
                       ccb.CreateChamCong(DateTime.Now.Month,DateTime.Now.Year,a.NhanVienID);
                   }
                   XtraMessageBox.Show("Đã tạo bảng chấm công thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

               }

                else
                    return;
            }
            this.Cursor = Cursors.WaitCursor;
            uclLuongNhanVien sv = new uclLuongNhanVien();
            sv.Dock = DockStyle.Fill;
            tabTinhLuong.Controls.Add(sv);
            tabTinhLuong.PageVisible = true;
            tabMain.SelectedTabPage = tabTinhLuong;
            this.Cursor = Cursors.Default;
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmOption frm = new FrmOption();
            frm.ShowDialog();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            uclNhanVien sv = new uclNhanVien();
            sv.Dock = DockStyle.Fill;
            tabNhanVien.Controls.Add(sv);
            tabNhanVien.PageVisible = true;
            tabMain.SelectedTabPage = tabNhanVien;
            this.Cursor = Cursors.Default;
        }

        private void barChamCong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            frmChamCong frm = new frmChamCong();
            frm.TopLevel = false;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Dock = DockStyle.Fill;
            tabChamCong.Controls.Add(frm);
           
            tabChamCong.PageVisible = true;
            tabMain.SelectedTabPage = tabChamCong;
            frm.Show();
            this.Cursor = Cursors.Default;
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            
        }
    }
}